// gjw/pages/doubao/send.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tishis:false,
    val:true,
    mp:true,
    tu:false,
    array: [],
    index:0,
    imgSrc:'../images/tu.png',
    objectArray: [
      {
        id: 0,
        name: '铜器'
      },
      {
        id: 1,
        name: '名石'
      },
      {
        id: 2,
        name: '玉器'
      },
      {
        id: 3,
        name: '扇木器'
      }
    ],
    tuijian: [
      { name: 1, value: '推荐'},
      { name: 0, value: '不推荐'},
    ],
    // zhiding: [
    //   { name: 1, value: '置顶'},
    //   { name: 0, value: '不置顶'},
    // ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   	var that=this 
		app.util.request({
			url: 'entry/wxapp/Isregister',
			data: { openid: wx.getStorageSync('openid') },
			success: function (res) {
				if (res.data.code == 200) {
					that.identy()
				}else {
					wx.redirectTo({
						url: '../index/register',
					})
				}
			}
		})
		app.util.request({
			url: 'entry/wxapp/isvideo',
			success: function (res) {
				if (res.data.code == 200) {
					if(res.data.res==1){
						that.setData({
							isvideoshow: false
						})
					} else if (res.data.res == 2) {
						that.setData({
							isvideoshow: true
						})
					}
					that.setData({
						isvideo:res.data.res
					})
				}
			}
		})
		app.util.request({
			url: 'entry/wxapp/Repucostdbf',
			data: { openid: wx.getStorageSync('openid') },
			success: function (res) {
				if (res.data.code == 200) {
					that.setData({
						rest: res.data.rest,
						restup: res.data.restup
					})
				}
			}
		})
		app.util.request({
			url: 'entry/wxapp/Recostis',
			data: { openid: wx.getStorageSync('openid') },
			success: function (res) {
				if (res.data.code == 200) {
					that.setData({
						total: res.data.total
					})
				}
			}
		})
   	that.setData({
				siteUrl: wx.getStorageSync('siteUrl')
   	})
   	that.leixing()
   	that.money()
   	
  
  
  },


  // 设置抖宝发布费用
  money: function (e) {
    var that = this
    app.util.request({
      url: 'entry/wxapp/Dbmoney',
      success: function (res) {
        
        that.setData({
          pay: res.data.res.publishfee,
          money: res.data.res.upfee,
          //cash: res.data.res.topfee,//唐
        })
      }
    })
  },

  // 抖宝类型获取
  leixing:function(e){
    var that=this
    app.util.request({
      url:'entry/wxapp/catestop',
      success:function(res){
        var arr=res.data.res
        var array=[]
        for (var i = 0; i < arr.length; i++) {
          array.push(arr[i].cate)
        }
        that.setData({
          array: array,
          fl:arr
        })
      }
    })
  },  

  // 判断身份
  identy:function(e){
    var that=this
		var openid = wx.getStorageSync('openid')
    app.util.request({
      url:'entry/wxapp/Iscustomers',
      data:{openid:openid},
      success:function(res){
        
        if (res.data.code == 200 || res.data.code==204 ) {    //商家审核通过  商家
          that.setData({
            zt:1
          })
        } else if (res.data.code == 201 || res.data.code == 500 || res.data.code == 202) {    //商家审核未通过  用户
            that.setData({
              zt:0
            })
        }   
      }
    })
  },

  bindPickerChange: function (e) {
    var hide = true
    var show=false
    this.setData({
      index: e.detail.value,
      tishi:hide,
      val:show
    })
  },

  radioChangeTj: function (e) {
    //console.log('radio发生change事件，携带value值为：', e.detail.value)//没用，下面有tj,//唐
  },

  getVideo:function(e){
    var that = this
    var show = false
    var hide = true
    wx.chooseVideo({
      sourceType: ['album', 'camera'],
      maxDuration: 15,
      camera: 'back',
      success: function (res) {
        
        var src = res.tempFilePath
        
        if (res.duration < 15){
          that.setData({
            mp: show,
            tu: hide,
            src: src,
            videotime: res.duration
          })
          that.uploadVideo({
						url: wx.getStorageSync('siteUrl') + 'app/index.php?i=' + wx.getStorageSync('uniacid') + '&c=entry&a=wxapp&do=Uploadvideo&m=zh_gjw',
            path: src
          })
        } else {
          wx.showToast({
            title: '视频最长上传15秒',
            icon: 'none',
            duration: 3000
          })
        }
        

          
        
        // wx.uploadFile({
        //   url: getApp().globalData.siteUrl + 'app/index.php?i=' + getApp().globalData.uniacid + '&c=entry&a=wxapp&do=Uploadvideo&m=zh_gjw',
        //   filePath: res.tempFilePath,
        //   name: 'upload_file',
        //   formData:null,
        //   success:function(res){
        //     
        //     that.setData({
        //       src: res.data
        //     })
        //   }
        // })
      }
    })
  },

  uploadVideo: function (data) {
    var that = this
    var siteUrl = that.data.siteUrl
      // i = data.i ? data.i : 0,
      // success = data.success ? data.success : 0,
      // fail = data.fail ? data.fail : 0;

      wx.uploadFile({
        url:data.url,
        filePath: data.path,
        name: 'upload_file',
        formData: null,
        success: function (res) {
          
          if (res.data != '') {
            
            // success++;
            that.setData({
              videoSrc: res.data
            })
          }
          else {
            wx.showToast({
              icon: "loading",
              title: "请重试"
            })
          }
          
        },
        fail: (res) => {
          // fail++;
        },
        complete: () => {
          // data.success = success;
          // data.fail = fail;
          // that.uploadVideo(data);
          //   console.log('成功：' + success + " 失败：" + fail);
          } 
      })
    // wx.uploadFile({
    //   url: data.url,
    //   filePath: data.path[i],
    //   name: 'upload_file',
    //   formData: null,
    //   success: (resp) => {
    //     if (resp.data != '') {
    //       console.log(resp)
    //       success++;
    //       imgArray.push(resp.data)
    //       that.setData({
    //         imgArray: imgArray
    //       })
    //       console.log(i);
    //       console.log('上传商家轮播图时候提交的图片数组', imgArray)
    //     }
    //     else {
    //       wx.showToast({
    //         icon: "loading",
    //         title: "请重试"
    //       })
    //     }
    //   },
    //   fail: (res) => {
    //     fail++;
    //     console.log('fail:' + i + "fail:" + fail);
    //   },
    //   complete: () => {
    //     console.log(i);
    //     i++;
    //     if (i == data.path.length) {
    //       that.setData({
    //         images: data.path
    //       });
    //       wx.hideToast();
    //       console.log('执行完毕');
    //       console.log('成功：' + success + " 失败：" + fail);
    //     } else {
    //       console.log(i);
    //       data.i = i;
    //       data.success = success;
    //       data.fail = fail;
    //       that.upload(data);
    //     }

    //   }
    // });
  },

  getImg:function(e){
    var that = this
        
    var siteUrl=that.data.siteUrl  
    wx.chooseImage({
      count: 1, // 默认9
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
      success: function (res) {
        
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        var tempFilePaths = res.tempFilePaths

        wx.uploadFile({
					url: wx.getStorageSync('siteUrl') + 'app/index.php?i=' + wx.getStorageSync('uniacid') + '&c=entry&a=wxapp&do=Uploads&m=zh_gjw', //仅为示例，非真实的接口地址
          filePath: tempFilePaths[0],
          name: 'upload_file',
          formData: {
            'user': 'test'
          },
          success: function (res) {
            var data = res.data
            
            that.setData({
              videoImg:data,
              imgSrc: siteUrl +'attachment/'+data
            })
          }
        })

        
      }
    })
  },
  

  sub:function(e){
    var that=this
    var formid = e.detail.formId;
    var openid = wx.getStorageSync('openid')
    var src = that.data.src
    var videoSrc = that.data.videoSrc
    var videoImg=that.data.videoImg
    var arr=e.detail.value
    var lx = arr.lx
    var arry=that.data.fl
    var fl=arry[lx].id
    var name = arr.name
    var content = arr.content
    var tj = arr.tj
    var pay = that.data.pay
    var money = that.data.money
    var zt=that.data.zt
    if(zt==1){
      var price = arr.price 
      var yunfei = arr.yunfei  
    }
    if (videoImg == undefined) {
      wx.showToast({
        title: '请上传抖宝主图',
        icon: 'none',
      })
    }else if(lx==''){
      wx.showToast({
        title: '请选择要发布的抖宝类型',
        icon: 'none',
      })
    } else if (name=="") {
      wx.showToast({
        title: '请填写宝贝的名称',
        icon: 'none',
      })
    } else if (price == "") {
      wx.showToast({
        title: '请填写宝贝的价格',
        icon: 'none',
      })
    } else if (yunfei == "") {
      wx.showToast({
        title: '请填写宝贝的运费',
        icon: 'none',
      })
    }  else if (content == "") {
      wx.showToast({
        title: '请填写宝贝的详情',
        icon: 'none',
      })
    } else if (tj == "") {
      wx.showToast({
        title: '请选择您的宝贝是否需要推荐',
        icon: 'none',
      })
		} else if (that.data.isvideo==1&&src == undefined) {
			wx.showToast({
				title: '请上传抖宝视频',
				icon: 'none',
			})
		} else{
			//发布方式（商家用户、信誉、发布费、推荐）：1、0000；2、0001;3、1000；4、1001；5、1010；6、1011；7、1(00)00；8、1(00)01；9、1(00)10；10、1(00)11；11、1(01)00；12、1(01)01；13、1(01)10；14、1(01)11；15、1(10)00；16、1(10)01；17、1(10)10；18、1(10)11；19、1(11)00；20、1(11)01；21、1(11)10；22、1(11)11;23、0001(0);24、1(00)01(0);25、1001(0);26、1(10)01(0)
			if (zt == 0) {
				app.util.request({
					url: 'entry/wxapp/Dbpublish',
					data: {
						formid: formid, openid: openid, dbname: name, c_id: fl, detail: content, video: videoSrc, videoimg: videoImg
					},
					success: function (res) {
						that.setData({
							res_id: res.data.res_id
						})
						var res_id = that.data.res_id
						if (res.data.code == 200) {
							// 支付
							if (tj == 0) {
								app.util.request({
									url: 'entry/wxapp/Dbsuccess',
									data: {
										upstate: tj, res_id: res_id, alltype: 1, openid: wx.getStorageSync('openid')
									},
									success: function (res) {
										// console.log(zd)
										wx.showModal({
											title: '提示',
											content: '提交成功，请耐心等待审核通过',
											showCancel: false,
											success: function (res) {
												if (res.confirm) {
													wx.reLaunch({
														url: '../index/index',
													})
												}
											}
										})
									}
								})
							} else if (tj == 1) {
								if(money>0){
									app.util.request({
										url: 'entry/wxapp/dbpay',
										data: {
											openid: openid, upfee: money, upstate: tj, res_id: res_id
										},
										success: function (pres) {
											wx.requestPayment({
												'timeStamp': pres.data.timeStamp,
												'nonceStr': pres.data.nonceStr,
												'package': pres.data.package,
												'signType': 'MD5',
												'paySign': pres.data.paySign,
												'success': function (res) {
													app.util.request({
														url: 'entry/wxapp/Dbsuccess',
														data: {
															upstate: tj, res_id: res_id, alltype: 2, openid: wx.getStorageSync('openid')
														},
														success: function (res) {
															// console.log(zd)
															wx.showModal({
																title: '提示',
																content: '提交成功，请耐心等待审核通过',
																showCancel: false,
																success: function (res) {
																	if (res.confirm) {
																		wx.reLaunch({
																			url: '../index/index',
																		})
																	}
																}
															})
														}
													})
												},
												'fail': function (res) {
													;
													wx.showToast({
														title: '支付失败',
														icon: "loading",
													})
												}
											})
										}
									})
								}else{
									app.util.request({
										url: 'entry/wxapp/Dbsuccess',
										data: {
											upstate: tj, res_id: res_id, alltype: 23, openid: wx.getStorageSync('openid')
										},
										success: function (res) {
											wx.showModal({
												title: '提示',
												content: '提交成功，请耐心等待审核通过',
												showCancel: false,
												success: function (res) {
													if (res.confirm) {
														wx.reLaunch({
															url: '../index/index',
														})
													}
												}
											})
										}
									})
								}
							}

						}

					}
				})
			}else if(zt==1){
        app.util.request({
          url: 'entry/wxapp/Dbpublish',
          data: {
            formid: formid, openid: openid, dbname: name, dbfee: price,exfee:yunfei, c_id: fl, detail: content, video: videoSrc, videoimg: videoImg
          },
          success: function (res) {
            that.setData({
              res_id: res.data.res_id
            })
            var res_id = that.data.res_id
            if (res.data.code == 200) {
							if (that.data.total > 0) {
								if (tj == 0 && that.data.rest == 0 && that.data.restup == 0) {
									if (pay > 0) {
										app.util.request({
											url: 'entry/wxapp/dbpay',
											data: {
												openid: openid, publishfee: pay, upfee: money, upstate: tj, res_id: res_id
											},
											success: function (pres) {
												wx.requestPayment({
													'timeStamp': pres.data.timeStamp,
													'nonceStr': pres.data.nonceStr,
													'package': pres.data.package,
													'signType': 'MD5',
													'paySign': pres.data.paySign,
													'success': function (res) {
														app.util.request({
															url: 'entry/wxapp/Dbsuccess',
															data: {
																upstate: tj, res_id: res_id, alltype: 9, openid: wx.getStorageSync('openid')
															},
															success: function (res) {
																wx.showModal({
																	title: '提示',
																	content: '提交成功，请耐心等待审核通过',
																	showCancel: false,
																	success: function (res) {
																		if (res.confirm) {
																			wx.reLaunch({
																				url: '../index/index',
																			})
																		}
																	}
																})
															}
														})

													},
													'fail': function (res) {
														;
														wx.showToast({
															title: '支付失败',
															icon: "loading",
														})
													}
												})
											}

										})
									} else {
										app.util.request({
											url: 'entry/wxapp/Dbsuccess',
											data: {
												upstate: tj, res_id: res_id, alltype: 7, openid: wx.getStorageSync('openid')
											},
											success: function (res) {
												wx.showModal({
													title: '提示',
													content: '提交成功，请耐心等待审核通过',
													showCancel: false,
													success: function (res) {
														if (res.confirm) {
															wx.reLaunch({
																url: '../index/index',
															})
														}
													}
												})
											}
										})
									}
								} else if(tj == 1 && that.data.rest == 0 && that.data.restup == 0) {
									if (pay > 0) {
										app.util.request({
											url: 'entry/wxapp/dbpay',
											data: {
												openid: openid, publishfee: pay, upfee: money, upstate: tj, res_id: res_id
											},
											success: function (pres) {
												wx.requestPayment({
													'timeStamp': pres.data.timeStamp,
													'nonceStr': pres.data.nonceStr,
													'package': pres.data.package,
													'signType': 'MD5',
													'paySign': pres.data.paySign,
													'success': function (res) {
														app.util.request({
															url: 'entry/wxapp/Dbsuccess',
															data: {
																upstate: tj, res_id: res_id, alltype: 10, openid: wx.getStorageSync('openid')
															},
															success: function (res) {
																wx.showModal({
																	title: '提示',
																	content: '提交成功，请耐心等待审核通过',
																	showCancel: false,
																	success: function (res) {
																		if (res.confirm) {
																			wx.reLaunch({
																				url: '../index/index',
																			})
																		}
																	}
																})
															}
														})

													},
													'fail': function (res) {
														;
														wx.showToast({
															title: '支付失败',
															icon: "loading",
														})
													}
												})
											}

										})
									} else {
										if(money>0){
											app.util.request({
												url: 'entry/wxapp/dbpay',
												data: {
													openid: openid, publishfee: pay, upfee: money, upstate: tj, res_id: res_id
												},
												success: function (pres) {
													wx.requestPayment({
														'timeStamp': pres.data.timeStamp,
														'nonceStr': pres.data.nonceStr,
														'package': pres.data.package,
														'signType': 'MD5',
														'paySign': pres.data.paySign,
														'success': function (res) {
															app.util.request({
																url: 'entry/wxapp/Dbsuccess',
																data: {
																	upstate: tj, res_id: res_id, alltype: 8, openid: wx.getStorageSync('openid')
																},
																success: function (res) {
																	wx.showModal({
																		title: '提示',
																		content: '提交成功，请耐心等待审核通过',
																		showCancel: false,
																		success: function (res) {
																			if (res.confirm) {
																				wx.reLaunch({
																					url: '../index/index',
																				})
																			}
																		}
																	})
																}
															})

														},
														'fail': function (res) {
															;
															wx.showToast({
																title: '支付失败',
																icon: "loading",
															})
														}
													})
												}

											})
										}else{
											app.util.request({
												url: 'entry/wxapp/Dbsuccess',
												data: {
													upstate: tj, res_id: res_id, alltype: 24, openid: wx.getStorageSync('openid')
												},
												success: function (res) {
													wx.showModal({
														title: '提示',
														content: '提交成功，请耐心等待审核通过',
														showCancel: false,
														success: function (res) {
															if (res.confirm) {
																wx.reLaunch({
																	url: '../index/index',
																})
															}
														}
													})
												}
											})
										}
									}
								} else if (tj == 0 && that.data.rest == 0 && that.data.restup > 0) {//11/13
									if (pay > 0) {
										app.util.request({
											url: 'entry/wxapp/dbpay',
											data: {
												openid: openid, publishfee: pay, upfee: money, upstate: tj, res_id: res_id
											},
											success: function (pres) {
												wx.requestPayment({
													'timeStamp': pres.data.timeStamp,
													'nonceStr': pres.data.nonceStr,
													'package': pres.data.package,
													'signType': 'MD5',
													'paySign': pres.data.paySign,
													'success': function (res) {
														app.util.request({
															url: 'entry/wxapp/Dbsuccess',
															data: {
																upstate: tj, res_id: res_id, alltype: 13, openid: wx.getStorageSync('openid')
															},
															success: function (res) {
																wx.showModal({
																	title: '提示',
																	content: '提交成功，请耐心等待审核通过',
																	showCancel: false,
																	success: function (res) {
																		if (res.confirm) {
																			wx.reLaunch({
																				url: '../index/index',
																			})
																		}
																	}
																})
															}
														})

													},
													'fail': function (res) {
														;
														wx.showToast({
															title: '支付失败',
															icon: "loading",
														})
													}
												})
											}

										})
									} else {
										app.util.request({
											url: 'entry/wxapp/Dbsuccess',
											data: {
												upstate: tj, res_id: res_id, alltype: 11, openid: wx.getStorageSync('openid')
											},
											success: function (res) {
												wx.showModal({
													title: '提示',
													content: '提交成功，请耐心等待审核通过',
													showCancel: false,
													success: function (res) {
														if (res.confirm) {
															wx.reLaunch({
																url: '../index/index',
															})
														}
													}
												})
											}
										})
									}
								} else if (tj == 1 && that.data.rest == 0 && that.data.restup > 0) {//12/14
									if (pay > 0) {
										app.util.request({
											url: 'entry/wxapp/dbpay',
											data: {
												openid: openid, publishfee: pay, upfee: money, upstate: tj, res_id: res_id, alltype: 14, openid: wx.getStorageSync('openid')
											},
											success: function (pres) {
												wx.requestPayment({
													'timeStamp': pres.data.timeStamp,
													'nonceStr': pres.data.nonceStr,
													'package': pres.data.package,
													'signType': 'MD5',
													'paySign': pres.data.paySign,
													'success': function (res) {
														app.util.request({
															url: 'entry/wxapp/Dbsuccess',
															data: {
																upstate: tj, res_id: res_id, alltype: 14, openid: openid
															},
															success: function (res) {
																wx.showModal({
																	title: '提示',
																	content: '提交成功，请耐心等待审核通过',
																	showCancel: false,
																	success: function (res) {
																		if (res.confirm) {
																			wx.reLaunch({
																				url: '../index/index',
																			})
																		}
																	}
																})
															}
														})

													},
													'fail': function (res) {
														;
														wx.showToast({
															title: '支付失败',
															icon: "loading",
														})
													}
												})
											}

										})
									} else {
										app.util.request({
											url: 'entry/wxapp/Dbsuccess',
											data: {
												upstate: tj, res_id: res_id, alltype: 12,openid:openid
											},
											success: function (res) {
												wx.showModal({
													title: '提示',
													content: '提交成功，请耐心等待审核通过',
													showCancel: false,
													success: function (res) {
														if (res.confirm) {
															wx.reLaunch({
																url: '../index/index',
															})
														}
													}
												})
											}
										})
									}
								} else if (tj == 0 && that.data.rest > 0 && that.data.restup == 0) {//15/17
									if (pay > 0) {
										app.util.request({
											url: 'entry/wxapp/Dbsuccess',
											data: {
												upstate: tj, res_id: res_id, alltype: 17,openid:openid
											},
											success: function (res) {
												wx.showModal({
													title: '提示',
													content: '提交成功，请耐心等待审核通过',
													showCancel: false,
													success: function (res) {
														if (res.confirm) {
															wx.reLaunch({
																url: '../index/index',
															})
														}
													}
												})
											}
										})
									} else {
										app.util.request({
											url: 'entry/wxapp/Dbsuccess',
											data: {
												upstate: tj, res_id: res_id, alltype: 15
											},
											success: function (res) {
												wx.showModal({
													title: '提示',
													content: '提交成功，请耐心等待审核通过',
													showCancel: false,
													success: function (res) {
														if (res.confirm) {
															wx.reLaunch({
																url: '../index/index',
															})
														}
													}
												})
											}
										})
									}
								} else if (tj == 1 && that.data.rest > 0 && that.data.restup == 0) {//16/18
									if (pay > 0) {
										app.util.request({
											url: 'entry/wxapp/dbpay',
											data: {
												openid: openid, publishfee: pay, upfee: money, upstate: tj, res_id: res_id ,alltype: 18
											},
											success: function (pres) {
												wx.requestPayment({
													'timeStamp': pres.data.timeStamp,
													'nonceStr': pres.data.nonceStr,
													'package': pres.data.package,
													'signType': 'MD5',
													'paySign': pres.data.paySign,
													'success': function (res) {
														app.util.request({
															url: 'entry/wxapp/Dbsuccess',
															data: {
																upstate: tj, res_id: res_id, alltype: 18,openid:openid
															},
															success: function (res) {
																wx.showModal({
																	title: '提示',
																	content: '提交成功，请耐心等待审核通过',
																	showCancel: false,
																	success: function (res) {
																		if (res.confirm) {
																			wx.reLaunch({
																				url: '../index/index',
																			})
																		}
																	}
																})
															}
														})

													},
													'fail': function (res) {
														;
														wx.showToast({
															title: '支付失败',
															icon: "loading",
														})
													}
												})
											}

										})
									} else {
										if(money>0){
											app.util.request({
												url: 'entry/wxapp/dbpay',
												data: {
													openid: openid, publishfee: pay, upfee: money, upstate: tj, res_id: res_id
												},
												success: function (pres) {
													wx.requestPayment({
														'timeStamp': pres.data.timeStamp,
														'nonceStr': pres.data.nonceStr,
														'package': pres.data.package,
														'signType': 'MD5',
														'paySign': pres.data.paySign,
														'success': function (res) {
															app.util.request({
																url: 'entry/wxapp/Dbsuccess',
																data: {
																	upstate: tj, res_id: res_id, alltype: 16
																},
																success: function (res) {
																	wx.showModal({
																		title: '提示',
																		content: '提交成功，请耐心等待审核通过',
																		showCancel: false,
																		success: function (res) {
																			if (res.confirm) {
																				wx.reLaunch({
																					url: '../index/index',
																				})
																			}
																		}
																	})
																}
															})

														},
														'fail': function (res) {
															;
															wx.showToast({
																title: '支付失败',
																icon: "loading",
															})
														}
													})
												}

											})
										}else{
											app.util.request({
												url: 'entry/wxapp/Dbsuccess',
												data: {
													upstate: tj, res_id: res_id, alltype: 26, openid: wx.getStorageSync('openid')
												},
												success: function (res) {
													wx.showModal({
														title: '提示',
														content: '提交成功，请耐心等待审核通过',
														showCancel: false,
														success: function (res) {
															if (res.confirm) {
																wx.reLaunch({
																	url: '../index/index',
																})
															}
														}
													})
												}
											})
										}
									}
								} else if (tj == 0 && that.data.rest > 0 && that.data.restup > 0) {//19/21
									if (pay > 0) {
										app.util.request({
											url: 'entry/wxapp/Dbsuccess',
											data: {
												upstate: tj, res_id: res_id, alltype: 21, openid: openid
											},
											success: function (res) {
												wx.showModal({
													title: '提示',
													content: '提交成功，请耐心等待审核通过',
													showCancel: false,
													success: function (res) {
														if (res.confirm) {
															wx.reLaunch({
																url: '../index/index',
															})
														}
													}
												})
											}
										})
									} else {
										app.util.request({
											url: 'entry/wxapp/Dbsuccess',
											data: {
												upstate: tj, res_id: res_id, alltype: 19
											},
											success: function (res) {
												wx.showModal({
													title: '提示',
													content: '提交成功，请耐心等待审核通过',
													showCancel: false,
													success: function (res) {
														if (res.confirm) {
															wx.reLaunch({
																url: '../index/index',
															})
														}
													}
												})
											}
										})
									}
								} else if (tj == 1 && that.data.rest > 0 && that.data.restup > 0) {//20/22
									if (pay > 0) {
										app.util.request({
											url: 'entry/wxapp/Dbsuccess',
											data: {
												upstate: tj, res_id: res_id, alltype: 22, openid: openid
											},
											success: function (res) {
												wx.showModal({
													title: '提示',
													content: '提交成功，请耐心等待审核通过',
													showCancel: false,
													success: function (res) {
														if (res.confirm) {
															wx.reLaunch({
																url: '../index/index',
															})
														}
													}
												})
											}
										})
									} else {
										app.util.request({
											url: 'entry/wxapp/Dbsuccess',
											data: {
												upstate: tj, res_id: res_id, alltype: 20,openid:openid
											},
											success: function (res) {
												wx.showModal({
													title: '提示',
													content: '提交成功，请耐心等待审核通过',
													showCancel: false,
													success: function (res) {
														if (res.confirm) {
															wx.reLaunch({
																url: '../index/index',
															})
														}
													}
												})
											}
										})
									}
								}
							}else{
								if (tj == 0) {
									if(pay>0){
										app.util.request({
											url: 'entry/wxapp/dbpay',
											data: {
												openid: openid, publishfee: pay, upfee: money, upstate: tj, res_id: res_id
											},
											success: function (pres) {
												wx.requestPayment({
													'timeStamp': pres.data.timeStamp,
													'nonceStr': pres.data.nonceStr,
													'package': pres.data.package,
													'signType': 'MD5',
													'paySign': pres.data.paySign,
													'success': function (res) {
														app.util.request({
															url: 'entry/wxapp/Dbsuccess',
															data: {
																upstate: tj, res_id: res_id,alltype:5
															},
															success: function (res) {
																wx.showModal({
																	title: '提示',
																	content: '提交成功，请耐心等待审核通过',
																	showCancel: false,
																	success: function (res) {
																		if (res.confirm) {
																			wx.reLaunch({
																				url: '../index/index',
																			})
																		}
																	}
																})
															}
														})

													},
													'fail': function (res) {
														;
														wx.showToast({
															title: '支付失败',
															icon: "loading",
														})
													}
												})
											}

										})
									}else{
										app.util.request({
											url: 'entry/wxapp/Dbsuccess',
											data: {
												upstate: tj, res_id: res_id,alltype:3
											},
											success: function (res) {
												wx.showModal({
													title: '提示',
													content: '提交成功，请耐心等待审核通过',
													showCancel: false,
													success: function (res) {
														if (res.confirm) {
															wx.reLaunch({
																url: '../index/index',
															})
														}
													}
												})
											}
										})
									}
								}else if(tj==1){
									if (pay > 0) {
										app.util.request({
											url: 'entry/wxapp/dbpay',
											data: {
												openid: openid, publishfee: pay, upfee: money, upstate: tj, res_id: res_id
											},
											success: function (pres) {
												wx.requestPayment({
													'timeStamp': pres.data.timeStamp,
													'nonceStr': pres.data.nonceStr,
													'package': pres.data.package,
													'signType': 'MD5',
													'paySign': pres.data.paySign,
													'success': function (res) {
														app.util.request({
															url: 'entry/wxapp/Dbsuccess',
															data: {
																upstate: tj, res_id: res_id,alltype:6
															},
															success: function (res) {
																wx.showModal({
																	title: '提示',
																	content: '提交成功，请耐心等待审核通过',
																	showCancel: false,
																	success: function (res) {
																		if (res.confirm) {
																			wx.reLaunch({
																				url: '../index/index',
																			})
																		}
																	}
																})
															}
														})

													},
													'fail': function (res) {
														;
														wx.showToast({
															title: '支付失败',
															icon: "loading",
														})
													}
												})
											}

										})
									} else {
										if(money>0){
											app.util.request({
												url: 'entry/wxapp/dbpay',
												data: {
													openid: openid, publishfee: pay, upfee: money, upstate: tj, res_id: res_id
												},
												success: function (pres) {
													wx.requestPayment({
														'timeStamp': pres.data.timeStamp,
														'nonceStr': pres.data.nonceStr,
														'package': pres.data.package,
														'signType': 'MD5',
														'paySign': pres.data.paySign,
														'success': function (res) {
															app.util.request({
																url: 'entry/wxapp/Dbsuccess',
																data: {
																	upstate: tj, res_id: res_id,alltype:4
																},
																success: function (res) {
																	wx.showModal({
																		title: '提示',
																		content: '提交成功，请耐心等待审核通过',
																		showCancel: false,
																		success: function (res) {
																			if (res.confirm) {
																				wx.reLaunch({
																					url: '../index/index',
																				})
																			}
																		}
																	})
																}
															})

														},
														'fail': function (res) {
															;
															wx.showToast({
																title: '支付失败',
																icon: "loading",
															})
														}
													})
												}

											})
										}else{
											app.util.request({
												url: 'entry/wxapp/Dbsuccess',
												data: {
													upstate: tj, res_id: res_id, alltype: 25, openid: wx.getStorageSync('openid')
												},
												success: function (res) {
													wx.showModal({
														title: '提示',
														content: '提交成功，请耐心等待审核通过',
														showCancel: false,
														success: function (res) {
															if (res.confirm) {
																wx.reLaunch({
																	url: '../index/index',
																})
															}
														}
													})
												}
											})
										}
									}
								}
							}
							// if (tj == 1) {
							// 	app.util.request({
							// 		url: 'entry/wxapp/dbpay',
							// 		data: {
							// 			openid: openid, publishfee: pay, upfee: money, upstate: tj, res_id: res_id
							// 		},
							// 		success: function (res) {
										
							// 			wx.requestPayment({
							// 				'timeStamp': res.data.timeStamp,
							// 				'nonceStr': res.data.nonceStr,
							// 				'package': res.data.package,
							// 				'signType': 'MD5',
							// 				'paySign': res.data.paySign,
							// 				'success': function (res) {
							// 					app.util.request({
							// 						url: 'entry/wxapp/Dbsuccess',
							// 						data: {
							// 							upstate: tj, res_id: res_id
							// 						},
							// 						success: function (res) {
							// 							wx.showModal({
							// 								title: '提示',
							// 								content: '提交成功，请耐心等待审核通过',
							// 								showCancel: false,
							// 								success: function (res) {
							// 									if (res.confirm) {
							// 										wx.reLaunch({
							// 											url: '../index/index',
							// 										})
							// 									}
							// 								}
							// 							})
							// 						}
							// 					})

							// 				},
							// 				'fail': function (res) {
							// 					;
							// 					wx.showToast({
							// 						title: '支付失败',
							// 						icon: "loading",
							// 					})
							// 				}
							// 			})
							// 		}

							// 	})
							// }else if(tj==0){
							// 	if(pay>0){
							// 		app.util.request({
							// 			url: 'entry/wxapp/dbpay',
							// 			data: {
							// 				openid: openid, publishfee: pay, upstate: tj, res_id: res_id
							// 			},
							// 			success: function (res) {
											
							// 				wx.requestPayment({
							// 					'timeStamp': res.data.timeStamp,
							// 					'nonceStr': res.data.nonceStr,
							// 					'package': res.data.package,
							// 					'signType': 'MD5',
							// 					'paySign': res.data.paySign,
							// 					'success': function (ress) {
							// 						app.util.request({
							// 							url: 'entry/wxapp/Dbsuccess',
							// 							data: {
							// 								upstate: tj, res_id: res_id
							// 							},
							// 							success: function (resss) {
							// 								wx.showModal({
							// 									title: '提示',
							// 									content: '提交成功，请耐心等待审核通过',
							// 									showCancel: false,
							// 									success: function (rres) {
							// 										if (rres.confirm) {
							// 											wx.reLaunch({
							// 												url: '../index/index',
							// 											})
							// 										}
							// 									}
							// 								})
							// 							}
							// 						})
							// 					}
							// 				})
							// 			}
							// 		})
							// 	}else{
              //     app.util.request({
              //       url: 'entry/wxapp/Dbsuccess',
              //       data: {
              //         upstate: tj, res_id: res_id
              //       },
              //       success: function (res) {
                      
                      
              //         wx.showModal({
              //           title: '提示',
              //           content: '提交成功，请耐心等待审核通过',
              //           showCancel: false,
              //           success: function (res) {
              //             if (res.confirm) {
              //               wx.reLaunch({
              //                 url: '../index/index',
              //               })
              //             }
              //           }
              //         })
              //       }
              //     })
							// 	}
							// }

            }
          }
        })
      }
    } 
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})